﻿<%@ Application Language="C#" %>

<script runat="server">


    void Application_BeginRequest(object sender, EventArgs e)
    {
        // Original fix credit to Stefan Mohr
        // Bug fix for MS SSRS Blank.gif 500 server error missing parameter IterationId
        // https://connect.microsoft.com/VisualStudio/feedback/details/556989/
        if (HttpContext.Current.Request.Url.PathAndQuery.StartsWith("/Reserved.ReportViewerWebControl.axd") &&
            !HttpContext.Current.Request.Url.ToString().ToLower().Contains("iteration") &&
            !String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["ResourceStreamID"]) &&
            HttpContext.Current.Request.QueryString["ResourceStreamID"].ToLower().Equals("blank.gif"))
        {
            Context.RewritePath(String.Concat(HttpContext.Current.Request.Url.PathAndQuery, "&IterationId=0"));
        }
    }
 
    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup

        Application["UsersLoggedIn"] = new System.Collections.Generic.List<string>();        
        
    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

        // NOTE: you might want to call this from the .Logout() method - aswell -, to speed things up

    }
       
</script>
